{extend name="common/base_page" /}

{block name="title"}组合项目管理{/block}

{block name="jscssfile"}
<link href="__STATIC__/easy_search/searchPlug.css?v={$site.version}" type='text/css'/>
{/block}

{block name="css"}
<style type="text/css">
body{ background: #ffffff; height:100vh; }
</style>
{/block}

{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card-body public-tpl-row1" style="padding: 0px;">
        <form class="layui-form" action="" id="info-form" lay-filter="info-form" onsubmit="return false;">
        <fieldset class="layui-elem-field layui-field-title"><legend>组合项目基本信息</legend></fieldset>
        <div class="layui-form-item">
            <div class="layui-inline"><label class="layui-form-label"><i class="c-red">*</i>组合编号</label>
                <div class="layui-input-inline">
                <input type="text" name="bianma" autocomplete="off" class="layui-input" value="{if $info.id gt 0}{$info.bianma}{else}{$new_bianhao}{/if}">
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label" id="tpl_zhenliao_label"><i class="c-red">*</i>组合名称</label>
                <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="name" autocomplete="off" class="layui-input" value="{$info.name}">
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label">组合类型</label>
                <div class="layui-input-inline">
                    <select name="zh_type" lay-filter="zh_type">
                        {volist name="zhxm_cate_list" id="zhtype"}
                            <option value="{$zhtype.id}" {if $info.zh_type eq $zhtype.id}selected="true"{/if}>{$zhtype.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline"><label class="layui-form-label">单位</label>
                <div class="layui-input-inline">
                    <select name="ls_unit">
                        {volist name="zhxm_unit_list" id="unit"}
                            <option value="{$unit.id}" {if $info.ls_unit eq $unit.id}selected="true"{/if}>{$unit.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label">地点</label>
                <div class="layui-input-inline">
                    <select name="address">
                        {volist name="zhxm_address_list" id="add"}
                            <option value="{$add.id}" {if $info.address eq $add.id}selected="true"{/if}>{$add.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label biaoben_label">标本/部位</label>
                <div class="layui-input-inline biaoben_body_html">
                    <input type="text" name="biaoben" autocomplete="off" class="layui-input" value="" readonly="true">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline"><label class="layui-form-label">拼音简码</label>
                <div class="layui-input-inline">
                <input type="text" name="py_code" autocomplete="off" class="layui-input" value="{$info.py_code}">
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label">五笔简码</label>
                <div class="layui-input-inline">
                <input type="text" name="wb_code" autocomplete="off" class="layui-input" value="{$info.wb_code}">
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label"><i class="c-red">*</i>组合单价</label>
                <div class="layui-input-inline">
                <input type="text" name="zh_price" autocomplete="off" class="layui-input" readonly="true" value="{$info.zh_price}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline"><label class="layui-form-label">备注</label>
                <div class="layui-input-inline" style="width:514px;">
                <input type="text" name="remarks" autocomplete="off" class="layui-input" value="{$info.remarks}"/>
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label"><i class="c-red">*</i>执行单价</label>
                <div class="layui-input-inline">
                <input type="text" name="price" autocomplete="off" class="layui-input" value="{$info.price}">
                </div>
            </div>
        </div>
        <div class="layui-form-item drugs_guige">
            <div class="layui-inline"><label class="layui-form-label">项目提成</label>
                <div class="layui-input-inline" style="width:120px;">
                    <select name="xm_tc_mode" lay-filter="xm_tc_mode">
                        <option value="0" {if $info.xm_tc_mode eq '0'}selected="true"{/if}>无提成</option>
                        <option value="1" {if $info.xm_tc_mode eq '1'}selected="true"{/if}>按提成比例</option>
                        <option value="2" {if $info.xm_tc_mode eq '2'}selected="true"{/if}>按固定金额</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline" style="width:80px;">
                    <input type="text" name="xm_tc_val" autocomplete="off" class="layui-input" value="{$info.xm_tc_val}">
                </div>
            </div>
            <label id="zhenliao_form_tc_unit">%</label>
            <div class="layui-inline"><label class="layui-form-label">启用标志</label>
                <div class="layui-input-inline">
                <input type="radio" name="status" value="1" title="已启用" {if $info.status eq '1' || !$info}checked="true"{/if}>
                <input type="radio" name="status" value="0" title="已停用" {if $info.status eq '0'}checked="true"{/if}>
                </div>
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title"><legend>子项目信息</legend></fieldset>
        <div class="layui-form-item" style="margin-bottom:0px;">
            <div class="layui-input-block" style="margin-left:0px;">
                  <div class="layui-inline">
                    <label class="layui-form-label">项目类型</label>
                    <div class="layui-input-inline" style="width:120px;">
                      <select id="sub_xm_type" name="sub_xm_type" lay-filter="sub_xm_type">
                          <option value="zhenliao">诊疗项目</option>
                          <option value="cailiao">材料项目</option>
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <div class="layui-input-inline">
                      <input type="text" name="keyword" id="keyword" maxlength="10" placeholder="请输入项目名称键词" autocomplete="off" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-inline">
                        <a class="layui-btn layui-btn-normal layui-btn-warm" onclick="$('#subListBox').empty();reloadListPrice();">全部清空</a>
                  </div>
            </div>
        </div>

            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body" style="margin-top:10px;padding:0px 15px;height: 300px;overflow-y: scroll;">
                        <table class="layui-table">
                          <colgroup>
                            <col width="120">
                            <col width="150">
                            <col width="250">
                            <col width="100">
                            <col width="100">
                            <col width="100">
                            <col>
                          </colgroup>
                          <thead>
                            <tr>
                              <th>项目类型</th>
                              <th>项目编号</th>
                              <th>项目名称</th>
                              <th>单价</th>
                              <th>数量</th>
                              <th>操作</th>
                            </tr>
                          </thead>
                          <tbody id="subListBox">
                          {volist name="table_list" id="vo"}
                            <tr data-type="{$vo.type}" data-id="{$vo.id}" data-price="{$vo.price}" data-json='{:json_encode($vo,JSON_UNESCAPED_UNICODE)}' id="tr_{$vo.type}_{$vo.id}">
                              <td>{$vo.type_txt}</td>
                              <td>{$vo.bianma}</td>
                              <td>{$vo.name}</td>
                              <td>{$vo.price}</td>
                              <td><input type="text" id="tr_ipt_{$vo.type}_{$vo.id}" autocomplete="off" class="layui-input" value="{$vo.num}" style="height: 28px;"></td>
                              <td><a class="layui-btn layui-btn-danger layui-btn-xs" onclick="delTr('#tr_{$vo.type}_{$vo.id}');">删除</a></td>
                            </tr>
                          {/volist}
                          </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-layout-admin">
              <div class="layui-input-block">
                <div class="layui-footer" style="left: 0;">
                  <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="info-form-savebtn1">保存</button>
                  <button type="reset" class="layui-btn layui-btn-danger" id="resetBtn">重置</button>
                  <a class="layui-btn layui-btn-primary" href="{:url('/index/dictionary.zhuhe/index')}">返回</a>
                </div>
              </div>
            </div>
            <input type="hidden" name="id" value="{$info.id}"/>
        </form>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="__INDEX__/js/common/hz2pinyin.js"></script>
<script src="__INDEX__/js/common/hz2wubi.js"></script>
<script src="__INDEX__/js/common/commonUtils.js?v={$site.version}"></script>
<script src="__STATIC__/easy_search/searchPlug.js?v={$site.version}"></script>
<script src="__INDEX__/js/zidian/zhuhe.js?v={$site.version}"></script>
<script type="text/javascript">
var _addType = 'zhenliao', _oldId = '{$info.id}';
$(function(){
  $("#info-form :input[name='bianma']").focus();
  $("#info-form :input[name='name']").bind('keyup',function(){
      comUtils.setPyAndWbCode(
        $(this),
        $("#info-form :input[name='py_code']"),
        $("#info-form :input[name='wb_code']")
      );
  });
  setTimeout(function(){
    layform.on('select(zh_type)', function(_tv){
      var _tmpHtml = getTypeHtml(_tv.value,'{$info.biaoben}');
      _setSelectHtml(_tv.value,_tmpHtml);
    });
    layform.on('select(xm_tc_mode)', function(_tv){
      console.log(_tv);
      if(_tv.value == '1')
      {
          $('#zhenliao_form_tc_unit').html('%');
      }else{
          $('#zhenliao_form_tc_unit').html('');
      }
    });
    layform.on('select(sub_xm_type)', function(_tv){
          _addType = _tv.value;
          $("#keyword").unbind('keyup');
          //搜索
          $.myEasySearch({
              selector:"#keyword",
              url:"{:url('index/dictionary.zhuhe/find_xmlist')}?type=" + _addType,
              height:200,
              header:[
                  {title:"项目编码",field:"bianma",width:100},
                  {title:"项目名称",field:"name",width:200},
                  {title:"单价",field:"price",width:80},
                  {title:"单位",field:"ls_unit_txt",width:60},
              ],
              click:function(d,o){
                  //设置-列表
                  setTableTbodyHtml(d);
              }
          });
    });
    setInfoTiChengUnitText('#info-form'); //设置--提成设置文字
    layform.verify({
      name: [/(.+){1,30}$/, '请输入项目名称']
    });
    //保存数据
    layform.on('submit(info-form-savebtn1)', function(data){
      data.field.table_list = getListData(); //列表信息
      //console.log(JSON.stringify(data.field)); //最终的提交信息
      layer.confirm('确定要保存组合项目信息吗？', {
          title:'保存',shade:[0.4,'#000000'],btn: ['确定','取消'],
          btn1:function(){
              layer.closeAll();
              _Index.ajax("{:url('index/dictionary.zhuhe/info')}",data.field,function(d){
                if(d.err == 0)
                {
                  $('#resetBtn').trigger('click');
                  layer.msg(d.msg, {time: 1000},function(){ 
                    window.location.href = "{:url('index/dictionary.zhuhe/index')}";
                  });
                }else{
                  layer.msg(d.msg, {time: 2000,anim: 4});
                }
              },'请稍候...');
          }
      });
      return false;
    });
    layform.render();
  },50);
  //搜索
  $.myEasySearch({
      selector:"#keyword",
      url:"{:url('index/dictionary.zhuhe/find_xmlist')}?type=" + _addType,
      height:200,
      header:[
          {title:"项目编码",field:"bianma",width:100},
          {title:"项目名称",field:"name",width:200},
          {title:"单价",field:"price",width:80},
          {title:"单位",field:"ls_unit_txt",width:60},
      ],
      click:function(d,o){
          //设置-列表
          setTableTbodyHtml(d);
      }
  });
});
function getTypeHtml(_type,_val)
{
  var html1 = '<select name="biaoben" lay-search>';
  {volist name="zhxm_beioben_list" id="bb"}
  if(_val == '{$bb.id}')
  {
    html1 += '<option value="{$bb.id}" selected="true">{$bb.name}</option>';
  }else{
    html1 += '<option value="{$bb.id}">{$bb.name}</option>';
  }
  {/volist}
  html1 += '</select>';
  var html2 = '<select name="biaoben" lay-search>';
  {volist name="buwei_list" id="bw"}
  if(_val == '{$bw.id}')
  {
    html2 += '<option value="{$bw.id}" selected="true">{$bw.name}</option>';
  }else{
    html2 += '<option value="{$bw.id}">{$bw.name}</option>';
  }
  {/volist}
  html2 += '</select>';
  var html3 = '<input type="text" name="biaoben" autocomplete="off" class="layui-input" value="" readonly="true">';
  if(_type == '1') return html1;
  if(_type == '2') return html2;
  if(_type == '3') return html3;
}
function _setSelectHtml(_type,_html)
{
  if(_type == 1)
  {
    $('.biaoben_label').html('<i class="c-red">*</i>标本');
  }
  if(_type == 2)
  {
    $('.biaoben_label').html('<i class="c-red">*</i>部位');
  }
  if(_type == 3)
  {
    $('.biaoben_label').html('标本/部位');
  }
  $('.biaoben_body_html').empty().append(_html);
  setTimeout(function(){
    layform.render('select');
  },50);
}
</script>
{if $info}
<script type="text/javascript">
$(function(){
    $('#subListBox tr').each(function(i,v){
          var _type = $(this).data('type'), _id = $(this).data('id'), _onePrice = $(this).data('price');
          var _idKeyName = _type + '_' + _id;
          $('#tr_ipt_'+_idKeyName).bind("keyup",function(){
              $(this).val($(this).val().replace(/[^\-?\d]/g,1));
              if(parseInt($(this).val()) <= 0)
              {
                $(this).val(1);
                layer.msg('请输入整数数值', {time: 1000}); 
              }
              reloadListPrice();
          });
          $('#tr_ipt_'+_idKeyName).focus(function(){$(this).select();}); 
    });
    var _tmpHtml = getTypeHtml('{$info.zh_type}','{$info.biaoben}');
    _setSelectHtml('{$info.zh_type}',_tmpHtml);
});
</script>
{else}
<script type="text/javascript">
$(function(){
    var _tmpHtml = getTypeHtml(1,'');
    _setSelectHtml(1,_tmpHtml);
});
</script>
{/if}
{/block}